home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / pt20pc.zip / SUPPORT.ASM < prev    next >
Assembly Source File  |  1991-02-04  |  17KB  |  692 lines

  1. DGROUP    GROUP    CONST,    _BSS,    _DATA
  2.     ASSUME  DS: DGROUP, SS: DGROUP, ES: DGROUP
  3. ;
  4. SUPPORT_TEXT    SEGMENT  WORD PUBLIC 'CODE'
  5. SUPPORT_TEXT    ENDS
  6. ;
  7. CONST    SEGMENT  WORD PUBLIC 'CONST'
  8. CONST    ENDS
  9. ;
  10. _BSS    SEGMENT  WORD PUBLIC 'BSS'
  11.     assume    ds:dgroup
  12.     extrn    _evtail:word
  13.     extrn    _evaddr:word
  14. _BSS    ENDS
  15. ;
  16. _DATA    SEGMENT  WORD PUBLIC 'DATA'
  17.     assume    ds:dgroup
  18. minus1    dw    -1
  19. minus2    dw    -2
  20. _DATA    ENDS
  21. ;
  22. SUPPORT_TEXT    SEGMENT  WORD PUBLIC 'CODE'
  23.     assume    cs:SUPPORT_TEXT
  24.     assume    ds:dgroup
  25.     public    _evinit, _mbintr
  26. ;
  27. ;
  28. ;************************ _repword *************************
  29. ; XTAG:repword
  30.         public    _repword
  31. ;
  32. ; repword(wordToReplicate, startAddress, numberOfReplications);
  33. ; char *startAddress;
  34. ; int wordToReplicate, numberOfReplications;
  35. ;
  36. _repword    proc    far
  37.         push    bp        ; save bp
  38.         mov    bp,sp        ; set up bp to access the arguments
  39.         push    di        ; save di
  40.         cld    ; set search direction to forwards
  41.         mov    ax,[bp+6]    ; ax = word to replicate
  42.         mov    di,[bp+8]    ; di = address to start reps
  43.         mov    cx,[bp+10]    ; cx = number of replications
  44.     rep    stosw            ; search for a newline
  45.         pop    di        ; restore di
  46.         pop    bp        ; restore bp
  47.         ret
  48. _repword    endp
  49. ;
  50. ;
  51. ; mouse event (software) interrupt handler
  52. ;
  53. pgmds    dw    ?
  54. ;
  55. ;
  56. ;************************ _movwords *************************
  57. ;
  58.         public    _movwords
  59. ;
  60. ; movwords(wordToReplicate, startAddress, numberOfReplications);
  61. ; char *startAddress;
  62. ; int wordToReplicate, numberOfReplications;
  63. ;
  64. _movwords    proc    far
  65.         push    bp        ; save bp
  66.         mov    bp,sp        ; set up bp to access the arguments
  67.         push    ds        ; save ds
  68.         push    es        ; save es
  69.         push    si        ; save si
  70.         push    di        ; save di
  71.         cld            ; set move direction to forwards
  72. ;
  73.         mov    ax,[bp+6]
  74.         mov    ds,ax
  75.         mov    si,[bp+8]    ; si = address of source data
  76.         mov    ax,[bp+10]    ; ax = word to replicate
  77.         mov    es,ax
  78.         mov    di,[bp+12]    ; di = address of destination data
  79. ;
  80.         mov    cx,[bp+14]    ; cx = number of replications
  81.         sar    cx,1        ; convert to a word count
  82.     rep    movsw            ; move the word
  83. ;
  84.         pop    di        ; restore di
  85.         pop    si        ; restore si
  86.         pop    es        ; restore es
  87.         pop    ds        ; restore ds
  88.         pop    bp        ; restore bp
  89.         ret
  90. _movwords    endp
  91. ;
  92. ;
  93. ;************************ _mbintr *************************
  94. ;
  95. _mbintr    proc    far
  96.     cli    ; disable hardware interrupts
  97. ;
  98. ; first save all the registers on entry
  99. ;
  100.     push    ds    ; save ds
  101.     push    si    ; save si
  102.     push    cx    ; save cx
  103.     push    bx    ; save bx
  104.     push    ax    ; save ax
  105. ;
  106.     push    dx    ; save dx
  107.     push    cx    ; save cx
  108.     push    bx    ; save bx
  109.     push    ax    ; save ax
  110. ;
  111. ; set us DS to Point's DS since the interrupt mechanism does not
  112. ; set it (how could it?)
  113. ;
  114.     mov    ds,pgmds
  115. ;
  116. ; now compute the address of the event slot to put this in
  117. ; and store the next value (no interrupts so not need to wait on the store)
  118. ;
  119.     mov    bx,_evaddr    ; address of the event array
  120.     mov    ax,_evtail    ; where the last event was put
  121.     inc    ax        ; move to the next event
  122.     cmp    ax,30        ; do modulo adjustment?
  123.     jl    l1
  124.     sub    ax,ax
  125. l1:
  126.     mov    _evtail,ax    ; record the increment so C can see it
  127.     mov    cl,3        ; 4 words/event x 2 bytes/word
  128.     shl    ax,cl        ; get an offset in 8 byte chunks
  129.     add    bx,ax        ; address of the next event
  130. ;
  131. ; store the four event words in the event slot
  132. ;
  133.     pop    [bx+0]    ; ax on entry moved to event slot
  134.     pop    [bx+2]    ; bx on entry moved to event slot
  135.     pop    [bx+4]    ; cx on entry moved to event slot
  136.     pop    [bx+6]    ; dx on entry moved to event slot
  137. ;
  138. ; restore registers
  139. ;
  140.     pop    ax
  141.     pop    bx
  142.     pop    cx
  143.     pop    si
  144.     pop    ds
  145. ;
  146. ; done
  147. ;
  148.     sti    ; re-enable interrupts
  149.     ret
  150. _mbintr    endp
  151. ;
  152. ;************************ _evinit *************************
  153. ;
  154. ; set up mbintr as the mouse software interrupt handler
  155. ;
  156. _evinit    proc    far
  157.     push    bp        ; save bp
  158.     mov    bp,sp
  159.     push    es        ; save es
  160.     mov    pgmds,ds    ; save ds for later
  161. ;
  162.     mov    ax,12        ; set subroutine mask
  163.     mov    cx,7FH        ; interrupt on mouse buttons
  164.     mov    dx,offset _mbintr; address of interrupt handler
  165.     push    cs        ; move cs to es
  166.     pop    es
  167.     int    51        ; mouse function call
  168. ;
  169.     pop    es
  170.     pop    bp
  171.     ret
  172. _evinit    endp
  173. ;
  174. ;************************ _getvect *************************
  175. ;
  176. ;
  177.         public    _getvect
  178. _getvect    PROC        far
  179.         push        bp            ; save bp
  180.         mov        bp,sp
  181.         push        es            ; save es
  182.         mov        al,[bp+6]        ; first arg is vector num
  183.         mov        ah,35H
  184.         int        21H            ; dos function call
  185.         mov        dx,es
  186.         mov        ax,bx
  187.         pop        es
  188.         pop        bp
  189.         ret
  190. _getvect    endp
  191. ;
  192.         public    _matchdn
  193. ;
  194. ; match = matchdn(text, textLength, pat, patlength);
  195. ; char *text, *pat, *match;
  196. ; int textLength, patLength;
  197. ;
  198. _matchdn    proc    far
  199.         push    bp
  200.         mov    bp,sp
  201.         push    si        ; save si
  202.         push    di        ; save di
  203.         push    es        ; save es
  204.         push    ds    ; move ds to es since di used a ds base
  205.         pop    es    ; in medium model not always(es==ds)
  206.         cld        ; set search direction to forward
  207.         mov    cx,[bp+8]    ; cx = length(text)
  208.         sub    cx,[bp+12]    ; cx = length(text)-length(pat)
  209.         jl    notFound    ; text shorter than pat
  210.         inc    cx        ;    + 1
  211.         mov    di,[bp+6]    ; di --> text
  212. loop1:
  213.         mov    si,[bp+10]    ; si --> pat
  214.         mov    al,[si]        ; al = first char in pat
  215.     repne    scasb            ; search for first char in pat
  216.         jne    notFound    ; last comparison was not equal
  217.                     ; so cx got to zero w/o finding char
  218.         mov    dx,cx        ; save text's cx
  219.         mov    bx,di        ; save text's di
  220.         mov    cx,[bp+12]    ; match for length of pat
  221.         dec    cx        ; we already matched the first char
  222.         jz    foundIt        ; pat is only one character long
  223.         mov    si,[bp+10]    ; the cmpsb uses this
  224.         inc    si        ; first char already was matched
  225.                     ; di is already set up
  226.     repe    cmpsb            ; compare the strings
  227.         je    foundIt        ; last compare was equal so we matched
  228.         mov    cx,dx        ; restore cx
  229.         mov    di,bx        ; the repe cmpsb changed di
  230.         jmp    loop1
  231. ;
  232. notFound:
  233.         xor    ax,ax        ; return 0 == NULL
  234.         jmp    retlab
  235. foundIt:
  236.         mov    ax,bx        ; bx = saved di (beginning of match)
  237.         dec    ax        ; di was one past the start of
  238.                     ; the match
  239. retlab:
  240.         pop    es
  241.         pop    di
  242.         pop    si
  243.         pop    bp
  244.         ret
  245. _matchdn    endp
  246. ;
  247. ;************************ _matchup *************************
  248. ;
  249. ;
  250.         public    _matchup
  251. ;
  252. ; match = matchup(text, textLength, pat, patlength);
  253. ; char *text, *pat, *match;
  254. ; int textLength, patLength;
  255. ;
  256. _matchup    proc    far
  257.         push    bp
  258.         mov    bp,sp
  259.         push    si        ; save si
  260.         push    di        ; save di
  261.         push    es        ; save es
  262.         push    ds    ; move ds to es since di used a ds base
  263.         pop    es    ; in medium model not always(es==ds)
  264.         mov    cx,[bp+8]    ; cx = length(text)
  265.         sub    cx,[bp+12]    ; cx = length(text)-length(pat)
  266.         jl    notupFound    ; text shorter than pat
  267.         inc    cx        ;    + 1
  268.         mov    di,[bp+6]    ; di --> text
  269.         add    di,cx        ; start cx bytes up since we are
  270.                     ; searching backwards (std)
  271. loopup:
  272.         mov    si,[bp+10]    ; si --> pat
  273.         mov    al,[si]        ; al = first char in pat
  274.         std            ; set search direction to backward
  275.     repne    scasb            ; search for first char in pat
  276.         jne    notupFound    ; last comparison was not equal
  277.                     ; so cx got to zero w/o finding char
  278.         mov    dx,cx        ; save text's cx
  279.         mov    bx,di        ; save text's di
  280.         mov    cx,[bp+12]    ; match for length of pat
  281.         dec    cx        ; we already matched the first char
  282.         jz    foundupIt    ; pat is only one character long
  283.         mov    si,[bp+10]    ; the cmpsb uses this
  284.         inc    si        ; first char already was matched
  285.                     ; di is already set up
  286.         cld            ; set search direction to forward
  287.     repe    cmpsb            ; compare the strings
  288.         je    foundupIt        ; last compare was equal so we matched
  289.         mov    cx,dx        ; restore cx
  290.         mov    di,bx        ; the repe cmpsb changed di
  291.         jmp    loopup
  292. ;
  293. notupFound:
  294.         xor    ax,ax        ; return 0 == NULL
  295.         jmp    retup
  296. foundupIt:
  297.         mov    ax,bx        ; bx = saved di (beginning of match)
  298.         dec    ax        ; di was one past the start of
  299.                     ; the match
  300. retup:
  301.         cld            ; set search direction to forward
  302.         pop    es
  303.         pop    di
  304.         pop    si
  305.         pop    bp
  306.         ret
  307. _matchup    endp
  308. ;
  309. ;************************ _match2dn *************************
  310. ;
  311.         public    _match2dn
  312. ;
  313. ; match = match2dn(text, textLength, ch1);
  314. ; char far *text;
  315. ; char *match, ch1;
  316. ; int textLength;
  317. ;
  318. _match2dn    proc    far
  319.         push    bp
  320.         mov    bp,sp
  321.         push    di        ; save di
  322.         push    es        ; save es
  323.         cld        ; set search direction to forward
  324. ;
  325. ; look for the first character
  326. ;
  327.         mov    di,[bp+6]    ; di --> text
  328.         mov    es,[bp+8]    ; es = segment of text
  329.         mov    cx,[bp+10]    ; cx = length(text)
  330.         mov    al,[bp+12]    ; al = first char in pat
  331.     repne    scasb            ; search for first char
  332.         je    found2It    ; last comparison w